package com.hivekion.quartz.taskJob;

import com.hivekion.common.Date.DateUtils;
import com.hivekion.quartz.domain.vo.JobModelVo;
import com.hivekion.quartz.service.IQuartzService;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @authot morning
 * @date 2021/8/4 9:55
 */
@Component
public class SplitSummaryJob implements Job {

      private static Logger log = LoggerFactory.getLogger(SplitSummaryJob.class);
      @Autowired
      IQuartzService quartzService;

      private void before() {

	    log.info("******SplitSummaryJob******");
      }

      @Override
      public void execute(JobExecutionContext context) {
	    before();
	    String name = context.getJobDetail().getKey().getName();

	    if (StringUtils.isNotBlank(name)) {
		  JobModelVo jobModelVo = quartzService.getInfo(name);
		  if (jobModelVo != null && StringUtils.isNotBlank(jobModelVo.getData())) {
			String data = jobModelVo.getData();
			int year = DateUtils.getNowYear();
		  }

	    }
	    String time =
		    LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
	    log.info(
		    "当前时间[{}],StatisticalParameterExecuteJob任务[{}]的线程名[{}]",
		    time,
		    name,
		    Thread.currentThread().getName());
	    after();
      }

      private void after() {

	    log.info("******SplitSummaryJob******");
      }
}
